public class DivisionByZero {
    public static void main(String[] args) {
        // 整数 / 整数 0
        runAndPrintException(() -> {
            int tmp = 1 / 0;
        });
        // 整数 / 浮点 0
        runAndPrintException(() -> {
            double tmp = 1 / 0.0;
        });
        // 浮点 / 整数 0
        runAndPrintException(() -> {
            double tmp = 1.0 / 0;
        });
        // 浮点 / 浮点 0
        runAndPrintException(() -> {
            double tmp = 1.0 / 0.0;
        });
    }

    public static void runAndPrintException(Runnable something) {
        try {
            something.run();
        } catch (Exception e) {
            System.out.println(e.getClass().getName() + ": " + e.getMessage());
            return;
        }
        System.out.println("未发生异常");
    }
}
